package com.daatak.mvc.common;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.daatak.mvc.domain.LovObject;

@Service
@Transactional
public class LovBean {
	
	@Autowired
	 private UtilityDao utilityDao;
	
	//TODO:consider this for cache, it should not hit the database everytime, 
	public Map<String, String> getList(){
	
		Map<String, String> lovList = new HashMap<String, String>();
		List<LovObject> listObject = utilityDao.getLovList("APP.LANGUAGE");
		for (Iterator iterator = listObject.iterator(); iterator.hasNext();) {
			LovObject lovObject = (LovObject) iterator.next();
			lovList.put(lovObject.getValue(), lovObject.getLabel());
			
		}
		return lovList;
	}
	public Map<String, String> list(String lovCode){
		
		Map<String, String> lovList = new HashMap<String, String>();
		List<LovObject> listObject = utilityDao.getLovList(lovCode);
		for (Iterator iterator = listObject.iterator(); iterator.hasNext();) {
			LovObject lovObject = (LovObject) iterator.next();
			lovList.put(lovObject.getValue(), lovObject.getLabel());
			
		}
		return lovList;
	}
}
